/*
    This file is part of Emu.

    Emu is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Emu is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Emu.  If not, see <http://www.gnu.org/licenses/>. */
#include "eprofile.h"
#include "eansidefines.h"

EProfile::EProfile()
{
    _colors[C_BLACK] = Qt::black;
    _colors[C_BLUE] = Qt::darkBlue;
    _colors[C_CYAN] = Qt::darkCyan;
    _colors[C_GREEN] = Qt::darkGreen;
    _colors[C_MAGENTA] = Qt::darkMagenta;
    _colors[C_RED] = Qt::darkRed;
    _colors[C_WHITE] = Qt::lightGray;
    _colors[C_YELLOW] = Qt::darkYellow;
    _colors[C_BOLD_BLACK] = Qt::darkGray;
    _colors[C_BOLD_BLUE] = Qt::blue;
    _colors[C_BOLD_CYAN] = Qt::cyan;
    _colors[C_BOLD_GREEN] = Qt::green;
    _colors[C_BOLD_MAGENTA] = Qt::magenta;
    _colors[C_BOLD_RED] = Qt::red;
    _colors[C_BOLD_WHITE] = Qt::white;
    _colors[C_BOLD_YELLOW] = Qt::yellow;
    _colors[C_FOREGROUND] = Qt::lightGray;
    _colors[C_BACKGROUND] = Qt::black;
    _colors[C_MSG_FOREGROUND] = Qt::yellow;
    _colors[C_MSG_BACKGROUND] = Qt::black;

    _hostName = "";
    _hostAddress = "";
    _hostPort = "";
}

QColor *EProfile::colors()
{
    QColor *c;
    c = new QColor[C_NUM_COLORS];
    memcpy(c, _colors, sizeof(QColor) * C_NUM_COLORS);
    return c;
}

QString EProfile::aliasReplace(QString text)
{
    int i;
    for (i = 0;i < _aliases.length();i++) {
        text.replace(_aliases.at(i).input(), _aliases.at(i).output());
    }

    return text;
}

QString EProfile::macroText(int keypress, int *sendto)
{
    int i;

    for (i = 0;i < _macros.length();i++) {
        EMacro macro = _macros.at(i);
        if (keypress == macro.press()) {
            *sendto = macro.to();
            return macro.data();
        }
    }

    return "";
}
